﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="TimeManagementSystem.Admin" %>
<%@ Import Namespace="TimeManagementSystem" %>
<%@ MasterType VirtualPath="~/Main.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link rel="stylesheet" href="/Resources/css/Admin.css"/>
    <script type="text/javascript" src="/Resources/js/Admin.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="content">
        <div class="hTxt"><span class="firstLetter">U</span><span class="lastLetters">sers</span></div>
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel runat="server" ID="updatePanel1">
            <ContentTemplate>
                <span><b>Select users: </b></span>
                <asp:DropDownList AutoPostBack="True" runat="server" ID="userSelection" OnTextChanged="Page_Load">
                    <asp:ListItem Value="1" Text="All">All</asp:ListItem>
                    <asp:ListItem Value="2" Text="Admin">Admin</asp:ListItem>
                    <asp:ListItem Value="3" Text="Manager">Manager</asp:ListItem>
                    <asp:ListItem Value="4" Text="Developer">Developer</asp:ListItem>
                    <asp:ListItem Value="5" Text="Tester">Tester</asp:ListItem>
                </asp:DropDownList>
                <br/>
                <% var creatorUser = Master.GetCreatorUser();
                   if (creatorUser.Status == "Admin" || creatorUser.Status == "Manager")
                   { %>
                        <div id="addUserBtn1" class="addUserBtn" onclick="addUserBtnClick();">Add new user</div>
                        <button class="editBtn" id="editBtn1" onclick="if(!editState) return editAdmin(); else return validateInput();">Edit</button>
                 <% } %>
                <table cellspacing="0">
                    <tr style="font-weight: bold; color: #8EBD00;">
                        <th style="width: 75px;">Number</th>
                        <th style="width: 75px;">Id</th>
                        <th style="text-align: left; width: 120px;">Name</th>
                        <th style="text-align: left; width: 120px;">Surname</th>
                        <th style="text-align: left; width: 160px;">Patronymic</th>
                        <th style="text-align: left; width: 230px;">Email</th>
                        <th style="text-align: left; width: 110px;">Login</th>
                        <th style="text-align: left; width: 110px;">Role</th>
                    </tr>
                    <% var i = 1;
                       var selectedUsers = GetSelectedUsers(Global.inputValid.dao.GetAllUsers());
                       foreach (var user in selectedUsers)
                        {
                            var clasees = i%2 == 0 ? "" : "odd";%>
                           <tr class="<%=clasees %> td">
                               <td class="adminNumb"><%=i %></td>
                               <td id="adminId<%=i%>" class="adminId"><%=user.Id %></td>
                               <td><input id="adminName<%=i%>" class="adminName" type="text" maxlength="30" readonly="readonly" value="<%=user.Name %>"/></td>
                               <td><input id="adminSname<%=i%>" class="adminSname" type="text" maxlength="30" readonly="readonly" value="<%=user.Surname %>"/></td>
                               <td><input id="adminPatron<%=i%>" class="adminPatron" type="text" maxlength="30" readonly="readonly" value="<%=user.Patronymic %>"/></td>
                               <td><input id="adminEmail<%=i%>" class="adminEmail" type="text" maxlength="30" readonly="readonly" value="<%=user.Email %>"/></td>
                               <td><input id="adminLogin<%=i%>" class="adminLogin" type="text" maxlength="30" readonly="readonly" value="<%=user.Login %>"/></td>
                               <td><select id="adminRole<%=i%>" disabled="disabled" class="adminRole"><option selected="selected" value="1"><%=user.Status %></option></select></td>
                               <td class="rm"><div class="removeBtn" onclick="return removeBtnClick(this, '<%=user.Id%>');"></div></td>
                           </tr>
                     <% i++;
                       } %>
                </table>
                <script>
                    var itemsCount = <%=selectedUsers.Count%>;
                </script>
                <% if (creatorUser.Status == "Admin" || creatorUser.Status == "Manager")
                   { %>
                        <div id="addUserBtn2" class="addUserBtn" onclick="addUserBtnClick();">Add new user</div>
                        <button class="editBtn" id="editBtn2" onclick="if(!editState) return editAdmin(); else return validateInput();">Edit</button>
                <% } %>
                <asp:HiddenField runat="server" ID="__EVENTTARGETCUR"/>
                <asp:HiddenField runat="server" ID="__EVENTARGUMENTCUR"/>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</asp:Content>

<asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolder2">
    <div id="addUserPop">
        <div id="closeAddUserPop"></div>
        <div class="headTxt">Add New User</div>
        <div class="headLine"></div>
        <div class="beforeInputTxt" id="nameTxt">Name:</div>
        <asp:TextBox runat="server" MaxLength="30" ID="nameBox" CssClass="inputField"/>
        <div class="beforeInputTxt" id="snameTxt">Surname:</div>
        <asp:TextBox runat="server" MaxLength="30" ID="snameBox" CssClass="inputField"/>
        <div class="beforeInputTxt" id="patronymicTxt">Patronymic:</div>
        <asp:TextBox runat="server" MaxLength="30" ID="patronymicBox" CssClass="inputField"/>
        <div class="beforeInputTxt" id="loginTxt">Login:</div>
        <asp:TextBox runat="server" MaxLength="30" ID="loginBox" CssClass="inputField"/>
        <div class="beforeInputTxt" id="passwordTxt">Password:</div>
        <asp:TextBox runat="server" MaxLength="30" ID="passwordBox" CssClass="inputField" TextMode="Password"/>
        <div class="beforeInputTxt" id="cpasswordTxt">Confirm password:</div>
        <asp:TextBox runat="server" MaxLength="30" ID="cpasswordBox" CssClass="inputField" TextMode="Password"/>
        <div class="beforeInputTxt" id="emailTxt">Email:</div>
        <asp:TextBox runat="server" MaxLength="30" ID="emailBox" CssClass="inputField"/>
        <div class="beforeInputTxt" id="roleTxt">Select role:</div>
        <asp:DropDownList runat="server" ID="roles">
            <asp:ListItem Value="1" Text="Admin">Admin</asp:ListItem>
            <asp:ListItem Value="2" Text="Manager">Manager</asp:ListItem>
            <asp:ListItem Value="3" Text="Developer">Developer</asp:ListItem>
            <asp:ListItem Value="4" Text="Tester">Tester</asp:ListItem>
        </asp:DropDownList>
        <asp:Button runat="server" ID="addBtn" OnClick="addBtn_OnClick" Text="Add User" OnClientClick="return validateUserAdd();"/>
    </div>
    </asp:Content>